/**
 * Created by Administrator on 2016/7/13.
 */
    angular.module('app', [ 'app.controllers', 'app.services', 'ui.router', 'flow', 'ui.bootstrap', 'frapontillo.bootstrap-switch'])

        .config(function($stateProvider, $httpProvider, $urlRouterProvider){
            //post方式传送的是json形式的数据
            $httpProvider.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded;charset=utf-8';
            var param = function (obj) {
                var query = '', name, value, fullSubName, subName, subValue, innerObj, i;

                for (name in obj) {
                    value = obj[name];
                    //instanceof 运算符1.判断一个实例是否属于某种类型
                    //                 2.可以在继承关系中用来判断一个实例是否属于它的父类型
                    if (value instanceof Array) {
                        for (i = 0; i < value.length; ++i) {
                            subValue = value[i];
                            fullSubName = name + '[' + i + ']';
                            innerObj = {};
                            innerObj[fullSubName] = subValue;
                            query += param(innerObj) + '&';
                        }
                    }
                    else if (value instanceof Object) {
                        for (subName in value) {
                            subValue = value[subName];
                            fullSubName = name + '[' + subName + ']';
                            innerObj = {};
                            innerObj[fullSubName] = subValue;
                            query += param(innerObj) + '&';
                        }
                    }
                    else if (value !== undefined && value !== null)
                        query += encodeURIComponent(name) + '=' + encodeURIComponent(value) + '&';
                }

                return query.length ? query.substr(0, query.length - 1) : query;
            };
             // localStorage.ipAddress = 'http://121.41.56.218:5007';
            localStorage.ipAddress = 'http://192.168.40.150:5007';
            // localStorage.ipAddress = 'http://192.168.30.156:5007';
            // localStorage.ipAddress = 'http://121.41.56.218:5005';

            $httpProvider.defaults.transformRequest = [function (data) {
                return angular.isObject(data) && String(data) !== '[object File]' ? param(data) : data;
            }];

            // 缓存配置
            if(!$httpProvider.defaults.headers.get){
                $httpProvider.defaults.headers.get = {};
            }
            $httpProvider.defaults.headers.common["X-Requested-with"] = 'XMLHttpRequest';
            $httpProvider.defaults.headers.get['Cache-Control'] = 'no-cache';
            $httpProvider.defaults.headers.get['Pragma'] = 'no-cache';

            if(undefined==localStorage.rightTag){
                localStorage.rightTag = "false";
                localStorage.oaOperationList = "[]";
            }else {
                localStorage.rightTag = "true";
            }

            $stateProvider
                //首页
                .state('homepage', {
                    url : '/homepage',
                    templateUrl : 'templates/homepage.html'
                })
                //活动管理
                .state('companyinfo', {
                    url : '/companyinfo',
                    templateUrl : 'templates/companyInfo.html'
                })
                //活动管理详情控制器
                .state('activitydetail', {
                    url : '/activitydetail',
                    templateUrl : 'templates/activityDetail.html'
                })
                //历史活动控制器
                .state('productions', {
                    url : '/productions',
                    templateUrl : 'templates/productions.html'
                })
                //创建活动控制器
                .state('companyaddress', {
                    url : '/companyaddress',
                    templateUrl : 'templates/companyAddress.html'
                })

            $urlRouterProvider.otherwise("homepage");
        })
        .factory('Data',function(){
            var initoaOperationList = function () {
                var o = null;
                if(localStorage.rightTag=="false"){
                    o = [
                        {
                            id : 2,
                            name : "招投标管理",
                            url : "#/" + localStorage.tenderUrl,
                            img : "tendermanagement.png",
                            imgActive : "tendermanagement-active.png",
                            enabled : false
                        },
                        {
                            id : 7,
                            name : "档案管理",
                            url : "#/filesmanagement",
                            img : "filesmanagement.png",
                            imgActive : "filesmanagement-active.png",
                            enabled : false
                        },
                        {
                            id : 8,
                            name : "合同管理",
                            url : "#/contractmanagement",
                            img : "contract.png",
                            imgActive : "contract-active.png",
                            enabled : false
                        }
                    ];
                    localStorage.oaOperationList = JSON.stringify(o);
                    localStorage.rightTag="true";
                }else {
                    o = JSON.parse(localStorage.oaOperationList);
                }
                return o;
            };
            return{
                tabs : [
                    {
                        id : 1,
                        name : '店铺首页',
                        url : '#/homepage'
                    },
                    {
                        id : 2,
                        name : '公司简介',
                        url : '#/companyinfo'
                    },
                    {
                        id : 3,
                        name : '产品介绍',
                        url : '#/productions'
                    },
                    {
                        id : 4,
                        name : '公司地址',
                        url : '#/companyaddress'
                    }
                ],
                operationList:[
                    {
                        id : 1,
                        name : "个人中心",
                        style : {"display":"block"},
                        // url : "#/btenderinfo",
                        urlList : [
                            {
                                id : 11,
                                name : "账户管理",
                                url : "#/accountmanager"
                            },
                            {
                                id : 12,
                                name : "个人推送数据",
                                url : "#/personalpushdata"
                            }
                        ]
                    },
                    {
                        id : 2,
                        name : "信息采集",
                        style : {"display":"block"},
                        // url : "#/btenderinfo",
                        urlList : [
                            {
                                id : 21,
                                name : "推送信息",
                                url : "#/allpush"
                            },
                            {
                                id : 22,
                                name : "江苏招标网",
                                url : "#/tenderinfo"
                            },
                            {
                                id : 23,
                                name : "我的上传",
                                url : "#/newtender"
                            }
                        ]
                    },
                    {
                        id : 3,
                        name : "我的投标",
                        style : {"display":"block"},
                        // url : "#/btenderinfo",
                        urlList : [
                            {
                                id : 33,
                                name : "项目招投标",
                                url : "#/tenderdoing"
                            },
                            {
                                id : 34,
                                name : "投标已完成",
                                url : "#/tenderdone"
                            }
                        ]
                    }
                ],
                oaOperationList:initoaOperationList(),
                fileOperationList:[]
            }
        })



